$(function () {
    //保险商品的表格
    $("#product_datagrid").datagrid({
        columns: [[
            {field: 'id', title: 'id', width: 100, hidden: true}, //hidden 隐藏显示该列
            {field: 'number', title: '保险编号', width: 100},//允许列改变大小
            {field: 'name', title: '保险产品', width: 100},
            {field: 'annualfee', title: '保险年费', width: 100}
        ]],
        striped: true,
        toolbar: "#pro_toolbar",
        fitColumns: true,
    })
    //会员弹出框
    $("#client_dialog").dialog({
        title: '正式客户',
        width: 600,
        height: 400,
        buttons: "#sure",
        closed: "true"
    })
    //会员表格数据
    $("#client_datagrid").datagrid({
        url: "/guaranteebill/queryClient?status=1",
        fit: true,
        columns: [[
            {field: 'id', title: 'id', width: 100, hidden: true}, //hidden 隐藏显示该列
            {field: 'name', title: '客户姓名', width: 100},//允许列改变大小
            {field: 'age', title: '年龄', width: 100},
            {
                field: 'gender', title: '性别', width: 100, formatter: function (value, row, index) {
                return value ? "女" : "男";

            }
            },
            {field: 'address', title: '客户地址', width: 100},
            {field: 'email', title: '邮箱', width: 100},
            {field: 'idCard', title: '身份证号', width: 100}
        ]],
        rownumbers: true,
        striped: true,
        pagination: true,
        fitColumns: true,
        singleSelect: true

    })
    //点击行保存记录
    var clientrows;
    $("#client_datagrid").datagrid({
        onClickRow: function (index, row) {
            clientrows = row;
        }
    })
    //传递客户资料给父窗口
    $("#sure").click(function () {
        $("#client_form").form("load", clientrows);
        $("#client_dialog").dialog("close");
    })

    //打开正式客户的窗口
    $("#client_btn").click(function () {
        $("#client_dialog").dialog("open");
    })
})

$(function () {
    /*------------------建议优化*/
//汽车弹出框
    $("#car_dialog").dialog({
        title: '汽车信息',
        width: 600,
        height: 400,
        buttons: "#sure_car",
        closed: "true"
    })

    //汽车表格数据
    $("#car_datagrid").datagrid({
        url: "/guaranteebill/queryCar",
        fit: true,
        columns: [[
            {field: 'id', title: 'id', width: 100, hidden: true}, //hidden 隐藏显示该列
            {field: 'carname', title: '车辆品牌', width: 100},//允许列改变大小
            {field: 'cartype', title: '车辆型号', width: 100},
            {field: 'displacement', title: '排气量/L', width: 100},
            {field: 'marketval', title: '市场估价', width: 100},
            {
                field: 'sort', title: '分类', width: 100, formatter: function (value, row, index) {
                return value ? "载人" : "载物";
            }
            },
            {field: 'carsizeId', title: '车辆大小', width: 100}
        ]],
        rownumbers: true,
        striped: true,
        pagination: true,
        fitColumns: true,
        singleSelect: true
    })

    //点击行保存记录
    var carrows;
    $("#car_datagrid").datagrid({
        onClickRow: function (index, row) {
            carrows = row;
        }
    })


    //传递客户资料给父窗口
    $("#sure_car").click(function () {
        $("#car_form").form("load", carrows);
        $("#car_dialog").dialog("close");
    })

    //打开汽车信息的窗口
    $("#car_btn").click(function () {
        $("#car_dialog").dialog("open");
    })
})


//保险弹框
$(function () {

    //弹出框
    $("#pro_dialog").dialog({
        title: '产品信息',
        width: 600,
        height: 400,
        buttons: "#sure_pro",
        closed: "true"
    })

    //点击行保存记录
    var prorows;
    var fee;
    var pid
    $("#pro_datagrid").datagrid({
        onClickRow: function (index, row) {
            prorows = row;
            fee = row.annualfee //保险年费
            pid = row.id;  //获取产品id
        }
    })

    //传递客户资料给父窗口
    $("#sure_pro").click(function () {
        //console.log(prorows)
        $("#product_datagrid").datagrid("appendRow", prorows);
        console.log(prorows)
        $("#pro_dialog").dialog("close");
    })

    $("#year").textbox({
        onChange: function (year) {
            console.log(prorows)
        }
    })

    //保存暂存单
    $("#submitBtn").click(function () {
        $("#client_form").form("submit", {
            url: '/guaranteebill/saveClient',
            success: function (data) {
                $("#pro_form").form("submit", {
                    url: '/guaranteebill/saveProduct?pid=' + pid,
                    success: function (data) {
                        $("#car_form").form("submit", {
                            url: '/guaranteebill/saveCar',
                            success: function (data) {
                                $.get("/guaranteebill/saveBill")
                            },
                            onSubmit: function (data) {
                                $.messager.alert('警告', '保存成功');
                                $.get("/guaranteebill/storage")
                            }
                        })
                    }
                })
            }
        })
    })


    $('#limitYear').textbox({
        onChange: function (value) {
            $("#totalAmount").text(value * fee);
        }
    });
})


function queryProduct() {
    var agency = $("#agency").combobox("getValue");
    $("#pro_datagrid").datagrid({
        queryParams: {
            agencyId: agency
        }
    })
    $("#pro_dialog").dialog("open");
    $("#pro_datagrid").datagrid({
        fit: true,
        url: "/productInfo/queryByAgency?agencyId=" + agency,//agencyId='+$("#agency").combobox("getValue"),
        columns: [[
            {field: 'id', title: 'id', width: 100, hidden: true}, //hidden 隐藏显示该列
            {field: 'number', title: '保险编号', width: 100},//允许列改变大小
            {field: 'name', title: '保险产品', width: 100},
            {field: 'annualfee', title: '保险年费', width: 100}
        ]],
        rownumbers: true,
        striped: true,
        toolbar: "#pro_toolbar",
        pagination: true,
        fitColumns: true
    })
}
































